import { Controller, Get } from '@nestjs/common';
import { MiniappBannerService } from './miniapp-banner.service';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthTenant } from '~/modules/tenant/tenant.decorator';
import { TenantEntity } from '~/modules/tenant/tenant.entity';
import { Public } from '~/modules/auth/decorators/public.decorator';
import { ApiTenantHeader } from '~/common/decorators/api-header-tenant.decorator';
import { BannerEntity } from '~/modules/banner/banner.entity';

@ApiTags('Banner - 轮播图')
@ApiBearerAuth()
@Controller('banner')
export class MiniappBannerController {
  constructor(private readonly miniappBannerService: MiniappBannerService) {}

  @Public()
  @Get()
  @ApiTenantHeader()
  @ApiOperation({ summary: '获取小程序banner' })
  async getMiniappBanner(@AuthTenant() tenant: TenantEntity): Promise<BannerEntity[]> {
    return await this.miniappBannerService.getAll(tenant?.id ?? null);
  }

  // @Post()
  // @ApiOperation({ summary: '创建小程序banner' })
  // @ApiExcludeEndpoint()
  // @ApiBody({ type: CreateBannerDto })
  // async create(
  //   @Body() dto: CreateBannerDto,
  //   @AuthUser() user: IAuthUser,
  //   @AuthTenant() tenant: IAuthTenant
  // ): Promise<MiniappBannerEntity> {
  //   if (user.isAdmin) {
  //     if (tenant?.id) {
  //       dto.tenantId = tenant.id;
  //     } else {
  //       throw new BadRequestException(ErrorEnum.NO_TENANT);
  //     }
  //   }

  //   if (user.isSuperAdmin && !dto?.tenantId) {
  //     throw new BadRequestException(ErrorEnum.NO_TENANT);
  //   }

  //   return await this.miniappBannerService.create(dto);
  // }
}
